home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / plain C OS8 / Everything / Stuff.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-29  |  8.2 KB  |  409 lines  |  [TEXT/CWIE]

  1. /* Stuff.c */
  2.  
  3. #include <Types.h>
  4. #include <Quickdraw.h>
  5. #include <Controls.h>
  6. #include <Dialogs.h>
  7. #include <Events.h>
  8. #include <Lists.h>
  9. #include <Menus.h>
  10. #include <Resources.h>
  11. #include <Sound.h>
  12. #include <TextEdit.h>
  13. #include <ToolUtils.h>
  14. #include <Appearance.h>
  15. #include <stdlib.h>
  16.  
  17. #include "Globals.h"
  18. #include "ResourceDefs.h"
  19. #include "DoScrap.h"
  20. #include "Miscellany.h"
  21. #include "Scrolling.h"
  22. #include "ControlUtils.h"
  23. #include "Dispatcher.h"
  24. #include "DDocData.h"
  25. #include "EverythingEngine.h"
  26. #include "EverythingDoc.h"
  27. #include "Stuff.h"
  28.  
  29.  
  30. static    EverythingEngine*      GetEngine    (Stuff*    self);
  31.  
  32. static    void    DoUndo        (Stuff*    self);
  33. static    void    DoCut        (Stuff*    self);
  34. static    void    DoCopy        (Stuff*    self);
  35. static    void    DoPaste        (Stuff*    self);
  36. static    void    DoClear        (Stuff*    self);
  37. static    void    DoSelectAll        (Stuff*    self);
  38. static    void    DoShowClipboard    (Stuff*    self);
  39.  
  40. static    void    BuildTextListList        (ControlHandle        inList);
  41.  
  42. //----------
  43. Stuff*        NewStuff ()
  44. {
  45.     Stuff*        window;
  46.  
  47.     window = (Stuff*)malloc (sizeof (Stuff));
  48.     Stuff_Init (window);
  49.     SetClassID (window, classStuff);
  50.  
  51.     return window;
  52. }
  53.  
  54. //----------
  55. void    DeleteStuff (
  56.     Stuff*        window)
  57. {
  58.     Stuff_Free (window);
  59.     free (window);
  60. }
  61.  
  62. //----------
  63. void    Stuff_Create (
  64.     AMDoc*            inDoc,
  65.     DDocData*        inData)
  66. {
  67.     Stuff*        winObj = NewStuff ();
  68.  
  69.     if (winObj != nil) {
  70.         Stuff_Open (winObj, inDoc, inData);
  71.     }
  72. }
  73.  
  74. //----------
  75. void    Stuff_Init (
  76.     Stuff*        self)
  77. {
  78. }
  79.  
  80. //----------
  81. void    Stuff_Free (
  82.     Stuff*        self)
  83. {
  84. }
  85.  
  86. //----------
  87. EverythingEngine*    GetEngine (
  88.     Stuff*        self)
  89. {
  90.     return (EverythingEngine*) self->super.mDoc->mEngine;
  91. }
  92.  
  93. /*----------*/
  94. void    Stuff_Open (
  95.     Stuff*        self,
  96.     AMDoc*            inDoc,
  97.     DDocData*        inData)
  98. {
  99.     WindowPtr        window;
  100.     Handle            wftb;
  101.  
  102.     self->super.mDoc = inDoc;
  103.     self->mData = inData;
  104.     AddResponder ((AMSignaler*) self->mData, (AMResponder*) self);
  105.  
  106.     window = GetNewCWindow (WIND_Stuff, nil, (WindowPtr) -1L);
  107.     if (AMEngine_GetFilename (self->super.mDoc->mEngine) [0] != 0) {
  108.         SetWTitle (window, AMEngine_GetFilename (self->super.mDoc->mEngine));
  109.     }
  110.     self->super.mWindow = window;
  111.     ((EverythingDoc*)self->super.mDoc)->mStuffPtr = window;
  112.  
  113.     SetWindowKind (window, 'AM');
  114.     SetWRefCon (window, (long) self);
  115.     SetPort (window);
  116.     SetInfo (window);
  117.  
  118.     wftb = GetResource ('Wftb', WIND_Stuff);
  119.  
  120.     CreateRootControl (window, &self->super.mRootControl);
  121.  
  122.     self->super.vScroll = nil;
  123.     self->super.hScroll = nil;
  124.  
  125.  
  126.     self->mToolsHandle = GetNewControl (CNTL_Tools, window);
  127.     SetWindowItemFont (self->mToolsHandle, wftb, 1);
  128.     SetControlValue (self->mToolsHandle, GetTools (self->mData));
  129.  
  130.     self->mPopupsHandle = GetNewControl (CNTL_Popups, window);
  131.     SetWindowItemFont (self->mPopupsHandle, wftb, 2);
  132.  
  133.     self->mFromValuesList2Handle = GetNewControl (CNTL_FromValuesList2, window);
  134.     EmbedControl (self->mFromValuesList2Handle, self->mPopupsHandle);
  135.     SetWindowItemFont (self->mFromValuesList2Handle, wftb, 3);
  136.     SetControlValue (self->mFromValuesList2Handle, GetFromValuesList2 (self->mData));
  137.  
  138.     self->mFromMenuHandle = GetNewControl (CNTL_FromMenu, window);
  139.     EmbedControl (self->mFromMenuHandle, self->mPopupsHandle);
  140.     SetWindowItemFont (self->mFromMenuHandle, wftb, 4);
  141.     SetControlValue (self->mFromMenuHandle, GetFromMenu (self->mData));
  142.  
  143.     self->mListsHandle = GetNewControl (CNTL_Lists, window);
  144.     SetWindowItemFont (self->mListsHandle, wftb, 5);
  145.  
  146.     self->mTextListHandle = GetNewControl (CNTL_TextList, window);
  147.     EmbedControl (self->mTextListHandle, self->mListsHandle);
  148.     SetWindowItemFont (self->mTextListHandle, wftb, 6);
  149.     BuildTextListList (self->mTextListHandle);
  150.     SetListBoxChoice (self->mTextListHandle, GetTextList (self->mData));
  151.  
  152.     AdvanceKeyboardFocus (window);
  153.  
  154.     ShowWindow (window);
  155. }
  156.  
  157. /*----------*/
  158. void    Stuff_Close (
  159.     Stuff*        self)
  160. {
  161.     RemoveResponder ((AMSignaler*) self->mData, (AMResponder*) self);
  162.  
  163.     ((EverythingDoc*)self->super.mDoc)->mStuffPtr = nil;
  164.     SetInfo (nil);
  165.     HideWindow (self->super.mWindow);
  166.     DisposeWindow (self->super.mWindow);
  167.  
  168.     DeleteStuff (self);
  169. }
  170.  
  171. /*----------*/
  172. void    BuildTextListList (
  173.     ControlHandle        inControl)
  174. {
  175.     ListHandle        list;
  176.  
  177.     list = GetListHandle (inControl);
  178.     AddToList ("\pOne",   list);
  179.     AddToList ("\pTwo",   list);
  180.     AddToList ("\pThree", list);
  181.     AddToList ("\pInfinity",  list);
  182.  
  183. }
  184.  
  185. /*----------*/
  186. void    Stuff_Track (
  187.     Stuff*        self,
  188.     ControlHandle    whichControl,
  189.     short            whichPart,
  190.     Point            where)
  191. {
  192.     Rect            bounds;
  193.     short            newValue;
  194.  
  195.     if (whichControl == self->mToolsHandle) {
  196.         if (TrackClick (self->mToolsHandle, where) != 0) {
  197.             SetTools (self->mData, GetControlValue (self->mToolsHandle));
  198.         }
  199.     }
  200.     if (whichControl == self->mFromValuesList2Handle) {
  201.         if (TrackClick (self->mFromValuesList2Handle, where) != 0) {
  202.             SetFromValuesList2 (self->mData, GetControlValue (self->mFromValuesList2Handle));
  203.         }
  204.     }
  205.     if (whichControl == self->mFromMenuHandle) {
  206.         if (TrackClick (self->mFromMenuHandle, where) != 0) {
  207.             SetFromMenu (self->mData, GetControlValue (self->mFromMenuHandle));
  208.         }
  209.     }
  210.     if (whichControl == self->mTextListHandle) {
  211.         if (TrackClick (self->mTextListHandle, where)) {
  212.             SetTextList (self->mData, GetListBoxChoice (self->mTextListHandle));
  213.         }
  214.     }
  215. }
  216.  
  217. //----------
  218. void    Stuff_DataChanged (
  219.     Stuff*        self,
  220.     long            inDataID)
  221. {
  222.     if (inDataID == idTools) {
  223.         SetControlValue (self->mToolsHandle, GetTools (self->mData));
  224.     }
  225.     if (inDataID == idFromValuesList2) {
  226.         SetControlValue (self->mFromValuesList2Handle, GetFromValuesList2 (self->mData));
  227.     }
  228.     if (inDataID == idFromMenu) {
  229.         SetControlValue (self->mFromMenuHandle, GetFromMenu (self->mData));
  230.     }
  231. }
  232.  
  233. /*----------*/
  234. void    Stuff_MouseIn (
  235.     Stuff*        self,
  236.     Point            where,
  237.     short            modifiers)
  238. {
  239.     Rect        bounds;
  240.  
  241. }
  242.  
  243. //----------
  244. void    Stuff_ExitCurField (
  245.     Stuff*        self)
  246. {
  247.     ControlHandle    focus;
  248.  
  249.     GetKeyboardFocus (self->super.mWindow, &focus);
  250.  
  251.     if (focus == nil) {
  252.         // nothing to exit
  253.  
  254.     }
  255. }
  256.  
  257. /*----------*/
  258. void    Stuff_TypeIn (
  259.     Stuff*        self,
  260.     char            ch)
  261. {
  262.     ControlHandle    focus;
  263.     short            keyCode;
  264.  
  265.     GetKeyboardFocus (self->super.mWindow, &focus);
  266.  
  267.     if ((ch == charEnter)
  268.     ||  (ch == charReturn)) {
  269.         Stuff_ExitCurField (self);    // Dispatch
  270.     } else if (ch == charEsc) {
  271.     } else if (ch == charTab) {
  272.         AMWindow_DoTab ((AMWindow*) self, (curEvent.modifiers & optionKey) != 0);
  273.     } else if (focus != nil) {
  274.         keyCode = curEvent.message & keyCodeMask;
  275.         HandleControlKey (focus, keyCode, ch, curEvent.modifiers);
  276.         AMEngine_SetDirty (self->super.mDoc->mEngine);
  277.     } else {
  278.         SysBeep (1);
  279.     }
  280. }
  281.  
  282. /*----------*/
  283. void    Stuff_Resize (
  284.     Stuff*        self)
  285. {
  286.     /* application-specific code to resize items in window */
  287. }
  288.  
  289. /*----------*/
  290. void    Stuff_Scroll (
  291.     Stuff*        self,
  292.     short            newValue,
  293.     short            oldValue)
  294. {
  295.     /* application-specific code to scroll window */
  296.     if (gWhichScroll == self->super.vScroll) {
  297.     } else {    // horizontal
  298.     }
  299. }
  300.  
  301. //----------
  302. void    DoUndo (
  303.     Stuff*        self)
  304. {
  305. } // DoUndo
  306.  
  307. //----------
  308. void    DoCut (
  309.     Stuff*        self)
  310. {
  311.     TEHandle        curTE = AMWindow_GetCurTE ((AMWindow*) self);
  312.  
  313.     if (curTE != nil) {
  314.         TECut (curTE);
  315.         AMEngine_SetDirty (self->super.mDoc->mEngine);
  316.         scrapDirty = true;
  317.     }
  318. } // DoCut
  319.  
  320. //----------
  321. void    DoCopy (
  322.     Stuff*        self)
  323. {
  324.     TEHandle        curTE = AMWindow_GetCurTE ((AMWindow*) self);
  325.  
  326.     if (curTE != nil) {
  327.         TECopy (curTE);
  328.         scrapDirty = true;
  329.     }
  330. } // DoCopy
  331.  
  332. //----------
  333. void    DoPaste (
  334.     Stuff*        self)
  335. {
  336.     TEHandle        curTE = AMWindow_GetCurTE ((AMWindow*) self);
  337.  
  338.     if (curTE != nil) {
  339.         TEPaste (curTE);
  340.         AMEngine_SetDirty (self->super.mDoc->mEngine);
  341.     }
  342. } // DoPaste
  343.  
  344. //----------
  345. void    DoClear (
  346.     Stuff*        self)
  347. {
  348.     TEHandle        curTE = AMWindow_GetCurTE ((AMWindow*) self);
  349.  
  350.     if (curTE != nil) {
  351.         TEDelete (curTE);
  352.         AMEngine_SetDirty (self->super.mDoc->mEngine);
  353.     }
  354. } // DoClear
  355.  
  356. //----------
  357. void    DoSelectAll (
  358.     Stuff*        self)
  359. {
  360.     TEHandle        curTE = AMWindow_GetCurTE ((AMWindow*) self);
  361.  
  362.     if (curTE != nil) {
  363.         TESetSelect (0, 32767, curTE);
  364.     }
  365. } // DoSelectAll
  366.  
  367. //----------
  368. void    DoShowClipboard (
  369.     Stuff*        self)
  370. {
  371. } // DoShowClipboard
  372.  
  373. //----------
  374. Boolean        Stuff_DoCommand (
  375.     Stuff*        self,
  376.     long            inCommand)
  377. {
  378.     Boolean        result = true;
  379.  
  380.     switch (inCommand) {
  381.         case cmdUndo:
  382.                 DoUndo (self);
  383.             break;
  384.         case cmdCut:
  385.                 DoCut (self);
  386.             break;
  387.         case cmdCopy:
  388.                 DoCopy (self);
  389.             break;
  390.         case cmdPaste:
  391.                 DoPaste (self);
  392.             break;
  393.         case cmdClear:
  394.                 DoClear (self);
  395.             break;
  396.         case cmdSelectAll:
  397.                 DoSelectAll (self);
  398.             break;
  399.         case cmdShowClipboard:
  400.                 DoShowClipboard (self);
  401.             break;
  402.  
  403.         default:
  404.                 result = false;
  405.     } // switch
  406.  
  407.     return result;
  408. }
  409.